var controlPanel = {};

controlPanel.buttonHTML = function(img, title, action, divId) {
	var html = '';
	html += '<div class="controlPanelButton"';
	if (isSet(divId)) { html += ' id="' + divId + '"'; }
	html += ' onclick="' + action + ';">';
	html += '<img class="controlPanelIcon" src="images/controlPanel/' +
		img + '" title="' + title + '" alt="" />';
	html += '</div>';
	return html;
};

controlPanel.hideShowTables = function(div) {
	var x = getelid('kafenio');
	if (notSet(x)) { return; }

	if (Pexnidi.orataTrapezia) {
		x.platos = x.style.width;
		x.style.width = '0px';
	}
	else {
		x.style.width = x.platos;
	}

	x = getelid('sizitisi');
	if (notSet(x)) { return; }
	x.style.width = '0px';
	Pexnidi.ofelimosXoros();

	x = controlPanel.buttonImage(div);
	x.src = Pexnidi.orataTrapezia ? 'images/controlPanel/showTables.png' :
		'images/controlPanel/hideTables.png';
	Pexnidi.orataTrapezia = !(Pexnidi.orataTrapezia);			
};

controlPanel.exodos = function(div) {
	var x = controlPanel.buttonImage(div);
	x.oriSrc = x.src;
	x.src = 'images/working.gif';

	var req = newRequest();
	if (notSet(req)) { return; }

	req.onreadystatechange = function() {
		controlPanel.exodosCheck(req, x);
	};
	openRequest(req, 'fantasmatakia/exodosTrapezi');
	req.send();
};

controlPanel.exodosCheck = function(req, img) {
	if (req.readyState != 4) { return; }
	if (req.status != 200) {
		imgFail(img, img.oriSrc);
		return;
	}
	
	img.src = img.oriSrc;
};

controlPanel.nullImg = {};
controlPanel.buttonImage = function(div) {
	var x = div.getElementsByTagName('img');
	if (notSet(x)) { return controlPanel.nullImg; }
	if (notSet(x.length)) { return controlPanel.nullImg; }
	if (x.length < 1) { return controlPanel.nullImg; }
	return x[0];
}
